package com.relytosoft.mizar.media.analyze.services.controller.structure;

import com.alibaba.fastjson.JSONObject;
import com.relytosoft.dubhe.common.core.base.page.PageQuery;
import com.relytosoft.dubhe.common.core.object.ResponseResult;
import com.relytosoft.dubhe.common.log.annotation.OpLog;
import com.relytosoft.dubhe.common.log.enums.OpTypeEnum;
import com.relytosoft.mizar.media.analyze.api.pojo.dto.AyStructurePicByPicDto;
import com.relytosoft.mizar.media.analyze.api.pojo.vo.AyStructurePicByPicVo;
import com.relytosoft.mizar.media.analyze.services.service.structure.AyStructurePicByPicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lj
 * @date 2022/6/9 17:27
 */
@Api(tags = {"结构化以图搜图"})
@RestController
@RequestMapping("analyze/structure/picbypic")
public class AyStructurePicByPicController {

    @Resource
    private AyStructurePicByPicService ayStructurePicByPicService;

    @ApiOperation("结构化以图搜图创建")
    @OpLog(msg = "结构化以图搜图创建", opType = OpTypeEnum.INSERT)
    @PostMapping("create")
    public ResponseResult<Void> insert(@RequestBody AyStructurePicByPicDto ayStructurePicByPicDto) {
        boolean isSuccess = ayStructurePicByPicService.create(ayStructurePicByPicDto);
        //判断是否成功
        if (isSuccess) {
            return ResponseResult.ok();
        } else {
            return ResponseResult.fail();
        }
    }


    @ApiOperation("结构化以图搜图任务删除")
    @OpLog(msg = "结构化以图搜图任务删除", opType = OpTypeEnum.INSERT)
    @DeleteMapping("delete/{comparisonTaskId}")
    public ResponseResult<Void> delete(@PathVariable String comparisonTaskId) {
        //创建删除方法
        boolean isSuccess = ayStructurePicByPicService.delete(comparisonTaskId);
        //判断是否成功
        if (isSuccess) {
            return ResponseResult.ok();
        } else {
            return ResponseResult.fail();
        }
    }


    @OpLog(msg = "结构化以图搜图任务查询", opType = OpTypeEnum.SELECT)
    @ApiOperation("结构化以图搜图任务查询")
    @GetMapping("list")
    public ResponseResult<List<AyStructurePicByPicVo>> list() {
        return ResponseResult.ok(ayStructurePicByPicService.select());
    }


    @OpLog(msg = "结构化以图搜图任务结果查询", opType = OpTypeEnum.SELECT)
    @ApiOperation("结构化以图搜图任务结果查询")
    @GetMapping
    public ResponseResult<JSONObject> selectResult(PageQuery pageQuery,
                                                   @Param("comparisonTaskId")
                                                           String comparisonTaskId) {
        JSONObject jsonObject = ayStructurePicByPicService.selectResult(pageQuery, comparisonTaskId);
        return ResponseResult.ok(jsonObject);

    }
}